package com.qf.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.Product;
import com.qf.entity.Sale;
import com.qf.mapper.SaleMapper;
import com.qf.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者: 王鑫
 * 项目名: jxc2
 * 时间:2019/12/5  10:02
 * 描述:
 */
@Service
public class SaleServiceImpl implements SaleService {

    @Autowired
    private SaleMapper saleMapper;

    @Override
    public int insert(Sale sale) {

        sale.getProductId();
        sale.getPrice();
        sale.getQuantity();
        int i = saleMapper.insertSelective(sale);

        return i;
    }

    @Override
    public PageInfo<Sale> list(Integer pageNum, Integer pageSize, Integer flage) {
        List<Sale> saleList;
        PageHelper.startPage(pageNum, pageSize);
        if (flage == 1){
            PageHelper.orderBy("price desc");
            saleList=saleMapper.selectSaleAndProductAndUser();
        }else if (flage == 0){
            PageHelper.orderBy("sale_date desc");
            saleList=saleMapper.selectSaleAndProductAndUser();
        }else {
            saleList=saleMapper.selectSaleAndProductAndUser();
        }

       PageInfo<Sale> pageInfo = new PageInfo<>(saleList);

        return pageInfo;
    }
}
